#ifndef SRC_BASE_NETHELPERS_H_
#define SRC_BASE_NETHELPERS_H_

#include <list>

#include "base/asyncresolverinterface.h"
#include "base/signalthread.h"
#include "base/sigslot.h"
#include "base/socketaddress.h"

#if defined(OS_UNIX)
#include <netdb.h>
#include <stddef.h>
#elif defined(OS_WIN)
#include <winsock2.h>  // NOLINT
#endif

namespace vz {

class AsyncResolverTest;

// AsyncResolver will perform async DNS resolution, signaling the result on
// the SignalDone from AsyncResolverInterface when the operation completes.
class AsyncResolver : public SignalThread, public AsyncResolverInterface {
 public:
  AsyncResolver();
  virtual ~AsyncResolver() {}

  virtual void Start(const SocketAddress& addr);
  virtual bool GetResolvedAddress(int family, SocketAddress* addr) const;
  virtual int GetError() const {
    return error_;
  }
  virtual void Destroy(bool wait) {
    SignalThread::Destroy(wait);
  }

  const std::vector<IPAddress>& addresses() const {
    return addresses_;
  }
  void set_error(int error) {
    error_ = error;
  }

 protected:
  virtual void DoWork();
  virtual void OnWorkDone();

 private:
  SocketAddress addr_;
  std::vector<IPAddress> addresses_;
  int error_;
};

// rtc namespaced wrappers for inet_ntop and inet_pton so we can avoid
// the windows-native versions of these.
const char* inet_ntop(int af, const void *src, char* dst, socklen_t size);
int inet_pton(int af, const char* src, void *dst);

bool HasIPv6Enabled();
}  // namespace vz

#endif  // SRC_BASE_NETHELPERS_H_
